package jinyilw.swing.i18n;

import jinyilw.swing.SwingTools;

import java.util.ArrayList;

public class IString
{
	private final String key;
	private final String zhString;
	private final String enString;
	private String currentString, languageTag;

	public IString(String key, String zhString, String enString)
	{
		this.key = key;
		this.zhString = zhString;
		this.enString = enString;
	}

	public IString(String key, String zhString, String enString,
			boolean autoWrap)
	{
		this.key = key;
		if (autoWrap)
		{
			this.zhString = SwingTools.getHtmlText(zhString);
			this.enString = SwingTools.getHtmlText(enString);
		} else
		{
			this.zhString = zhString;
			this.enString = enString;
		}

	}

	public boolean needChange()
	{
		return languageTag != LanguageTools.languageTag
				&& LanguageTools.languageSettingEnable;
	}

	public String getI18nString()
	{
		if (LanguageTools.languageSettingEnable)
		{
			if (languageTag != LanguageTools.languageTag)
			{
				languageTag = LanguageTools.languageTag;
				currentString = LanguageTools.getText(key, zhString, enString);
			}
		} else
			currentString = zhString;
		return currentString;
	}

	@Override
	public String toString()
	{
		return getI18nString();
	}

	public static ArrayList<IString> createArray(String key, String zhString,
			String enString, int start, int end)
	{
		ArrayList<IString> list = new ArrayList<>();
		for (int i = start; i <= end; i++)
		{
			list.add(new IString(key + i, zhString + i, enString + i));
		}
		return list;
	}
}
